<template>
  <div class="page">
    <!-- 搜索区域 开始 -->
    <div class="el_card_box">
      <el-form :inline="true" size="small" :model="formInline" class="search_form">
        <el-form-item label="上架状态：">
          <shelf-select v-model="formInline.onShelf"></shelf-select>
        </el-form-item>
        <el-form-item label="关键词：">
          <el-input v-model="formInline.term" placeholder="请输入关键词"></el-input>
        </el-form-item>
      </el-form>
      <div class="search_btn_box">
        <el-button type="primary" size="small" @click="onSearch">筛选</el-button>
        <el-button type="default" size="small" @click="rest">清空筛选</el-button>
      </div>
    </div>
    <!-- 搜索区域 end -->

    <!-- 表格 开始 -->
    <div class="table_box">

      <!-- 操作区域 开始 -->
      <div class="action_box">
        <el-button type="primary" size="small" @click="addEvent()">新增材料</el-button>
        <el-button type="default" size="small" @click="openDialog()">设置热门搜索</el-button>
      </div>
      <!-- 操作区域 end -->

      <el-table ref="elTable" class="el_table" size="small" :data="tableData">
        <el-table-column prop="materialName" label="材料名称" width="400px">
          <template slot-scope="{row}">
            <TabMaterial :info="showFormatter(row)"></TabMaterial>
          </template>
        </el-table-column>
        <el-table-column prop="onShelf" label="上架状态" show-overflow-tooltip>
          <template slot-scope="{row}"><shelf-format :value="row.onShelf"></shelf-format></template>
        </el-table-column>
        <el-table-column prop="orderTime" label="排序时间" show-overflow-tooltip />
        <el-table-column prop="createdDate" label="创建时间" show-overflow-tooltip />
        <el-table-column prop="creator" label="创建人" show-overflow-tooltip />
        <el-table-column prop="orderNum" label="操作" width="120">
          <template slot-scope="{row}">
            <el-link type="primary" class="el_link" @click="addEvent(row.id)">编辑</el-link>
            <el-link type="danger" class="el_link" @click="removeMaterial(row)">删除</el-link>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination_list">
        <el-pagination background layout="sizes, total,prev, pager, next, jumper" :total="pageTotal" :page-size="pageSize" :page-sizes="pageSizes" :current-page.sync="pageNumber" @current-change="getList" @size-change="changePageSize" />
      </div>
    </div>
    <!-- 表格 end -->

    <!-- 设置热门搜索 弹框 开始 -->
    <HotWords v-model="showPopup" type="3"></HotWords>
    <!-- 设置热门搜索 弹框 end -->

  </div>
</template>

<script>
import { showToast, showModal, deepClone } from "@/common/util";
import TabHospital from "@/components/hospital";
import { GET_QUALIFICATION_MATERIAL_SEARCH, DELETE_QUALIFICATION_MATERIAL_INFO } from '@/http/information'
import HotWords from './hot.vue'
import TabMaterial from '@/components/material/index.vue'
export default {
  components: {
    TabHospital,
    HotWords,
    TabMaterial
  },
  data() {
    return {
      formInline: {},
      tableData: [],
      pageTotal: 0,
      pageNumber: 1,
      pageSizes: [10, 20, 50, 100],
      pageSize: 20,
      loading: false,
      showPopup: false
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    /** 重置 */
    rest() {
      this.formInline = {};
      this.getList();
    },

    /** 每页展示 */
    changePageSize(e) {
      this.pageSize = e;
      this.getList();
    },

    /** 获取参数 */
    getParams() {
      let oParams = JSON.parse(JSON.stringify(this.formInline));

      oParams.pageNumber = this.pageNumber;
      oParams.pageSize = this.pageSize;
      return oParams;
    },

    /** 获取列表 */
    getList() {
      let _this = this;
      let oParams = this.getParams();
      GET_QUALIFICATION_MATERIAL_SEARCH(oParams).then((res) => {
        let obj = res.data || {};
        _this.tableData = obj.list || [];
        _this.pageTotal = obj.totalElements;
      });
    },

    // 新增
    addEvent(id) {
      this.$router.push({ name: "informationMaterialAdd", query: { id: id } });
    },

    // 格式化医院数据
    showFormatter(row) {
      if (!row) {
        return {};
      }
      let o = deepClone(row)
      o.name = o.materialName;
      o.hospitalName = o.belongCompany;
      o.city = o.materialOriginPlace
      return o;
    },

    // 删除
    removeMaterial(row) {
      let _this = this;
      showModal({
        message: `确定删除该条数据吗？`,
        showCancelButton: true,
        success: function () {
          DELETE_QUALIFICATION_MATERIAL_INFO({ id: row.id }).then((res) => {
            if (res.code == 200) {
              showToast({
                message: "删除成功",
                type: "success",
              });
              _this.getList();
            }
          });
        },
      });
    },

    // 打开热门关键词弹框
    openDialog() {
      this.showPopup = true
    },

    // 搜索
    onSearch(){
      this.pageNumber = 1;
      this.getList()
    }


  },
};
</script>

<style lang="scss" scoped>
@import "@/assets/style/customer/index.scss";
</style>
